<?php
include('global.php');				//引入全局主文件
if(!isset($_SESSION['reader']))
{
	$mysql->msg('login.php', '请您先登录！');
}
$GLOBALS['pos'] = '<a href="book_borrow_back.php" target="_self">图书借还</a>';
$GLOBALS['title'] = '图书管理系统 - 图书借还';

$reader   = $action->_get_reader_info($_SESSION['readerid']);	//读取用户信息
$collect  = explode(',', $reader['collect']);					//收藏
$collect_num = empty($reader['collect']) ? 0 : count(explode(',', $reader['collect']));
$shoucang = $action->_get_reader_collect($collect);				//读取收藏
$borrow   = $action->_get_reader_borrow($_SESSION['readerid']);	//读取用户借书
$guoqi = $action->_get_guoqi($_SESSION['readerid']);			//读取过期图书
//借阅图书
if(isset($_GET['act']) && $_GET['act'] == 'borrow')
{
	$action->borrow_book($_GET['bid'], $_SESSION['readerid']);
}
//把图书移除收藏夹
if(isset($_GET['act']) && $_GET['act'] == 'moveout')
{
	$action->collect_moveout($_GET['bid'], $_SESSION['readerid']);
}
//添加到收藏夹
if(isset($_GET['act']) && $_GET['act'] == 'add_collect')
{
	$action->collect_add($_GET['bid'], $_SESSION['readerid']);
}
//续借图书
if(isset($_GET['act']) && $_GET['act'] == 'goon')
{
	$action->goon_borrow($_GET['bid'], $_SESSION['readerid']);
}
//归还图书
if(isset($_GET['act']) && $_GET['act'] == 'back')
{
	$action->book_back($_GET['bid'], $_SESSION['readerid']);
}
?>
<?php include('public/top.php');//引入头?>
<div class="bbleft">
  <div class="bbleft1">
    <h1>控制面板</h1>
    <ul>
    	<li class="bb1"><a href="#" name="open1">个人资料</a></li>
        <?php
        if(isset($_GET['c']))
		{
			echo '<script>
			$(function()
			{
				$(\'.open2\').trigger("click");
			});
			</script>';
		}
		?>
    	<li class="bb2"><a href="#" class="open2">我的收藏</a></li>
    	<li class="bb3"><a href="#" name="open3">已借图书</a></li>
    	<li class="bb4"><a href="#" name="open4">到期图书</a></li>
    </ul>
    </div>
</div>
<div class="bbright" id="bbright_id1">
<h3>&gt;&gt;个人资料</h3>
	<div class="bbright1">
    	<dl>
    		<dt><?php echo $_SESSION['reader'];?></dt>
            <dd>登录名：<?php echo $reader['userid'];?></dd>
            <dd>姓名：<?php echo $reader['username'];?></dd>
            <dd>性别：<?php echo $reader['sex'];?></dd>
            <dd>上次登录时间：<?php echo $reader['lasttime'];?></dd>
            <dd>email：<?php echo $reader['email'];?></dd>
            <dd>已借图书：<font color="#00CC00"><?php echo $reader['total'];?></font>&nbsp;本</dd>
            <dd>上次登录IP：<?php echo $reader['lastip'];?></dd>
            <dd>用户等级：<?php echo $reader['name'];?></dd>
            <dd>最大借书：<font color="#CC3300"><?php echo $reader['max_borrow'];?></font>&nbsp;本</dd>
            <dd>我的收藏：<?php echo $collect_num;?>&nbsp;本</dd>
    	</dl>
        <div class="change_info"><a href="login.php?action=change&uid=<?php echo $reader['userid'];?>">修改资料</a></div>
    </div>
</div>
<div class="bbright" id="bbright_id2">
<h3>&gt;&gt;我的收藏</h3>
	<div class="bbright1">
    <table>
    	<tr class="bbnoborder">
        	<td width="20%">图书名称</td>
        	<td width="15%">作者</td>
        	<td width="15%">出版社</td>
        	<td width="15%">出版时间</td>
        	<td width="13%">可借复本</td>
        	<td width="22%">操作</td>
        </tr>
        <?php
		if(!empty($shoucang))
		{
			foreach($shoucang as $v)
			{
		?>
    	<tr>
        	<td width="20%"><?php echo '<a href="book_view.php?bookid=' . $v['bid'] . '">' . $v['name'] . '</a>';?></td>
			<td><?php echo $v['author'];?></td>
            <td><?php echo $v['pstore'];?></td>
            <td><?php echo d($v['pdate']);?></td>
            <td><?php echo $v['storage'];?>&nbsp;本</td>
            <td>
            <a class="borrow_add_confirm" href="book_borrow_back.php?act=borrow&bid=<?php echo $v['bid'];?>">点击借阅</a>
            <a class="borrow_move_confirm" href="book_borrow_back.php?act=moveout&bid=<?php echo $v['bid'];?>">移除</a>
            </td>
        </tr>
        <?php
			}
		}
		else
		{
		?>
  		<tr>
        	<td colspan="6">收藏夹暂无图书</td>
        </tr>
        <?php	
		}
		?>
    </table>
    </div>
</div>
<div class="bbright" id="bbright_id3">
<h3>&gt;&gt;已借图书</h3>
	<div class="bbright1">
    <table>
    	<tr class="bbnoborder">
        	<td width="20%">图书名称</td>
        	<td width="15%">作者</td>
        	<td width="20%">借阅时间</td>
        	<td width="20%">应还时间</td>
        	<td width="13%">续借</td>
        	<td width="12%">归还</td>
        </tr>
        <?php
		if(!empty($borrow))
		{
			foreach($borrow as $v)
			{
		?>
    	<tr>
        	<td width="20%"><?php echo '<a href="book_view.php?bookid=' . $v['bid'] . '">' . $v['name'] . '</a>';?></td>
			<td><?php echo $v['author'];?></td>
            <td><?php echo d($v['borrowdate']);?></td>
            <td><?php echo d($v['backdate']);?></td>
            <td>
<?php 
echo $v['goon'] == 1 ? '<font color="#CC0000">已续借</font>' : '<a href="book_borrow_back.php?act=goon&bid=' . $v['bid'] . '">点此续借</a>';
?>
			</td>
            <td>
<?php
echo $v['isback'] == 1 ? '<font color="#00CC00">已归还</font>' : '<a href="book_borrow_back.php?act=back&bid=' . $v['bid'] . '">点此归还</a>';
?>
			</td>
        </tr>
        <?php
			}
		}
		else
		{
			echo '<tr><td colspan="6">暂无已借图书</td></tr>';
		}
		?>
    </table>
    </div>
</div>
<div class="bbright" id="bbright_id4">
<h3>&gt;&gt;到期图书</h3>
	<div class="bbright1">
    <table>
    	<tr class="bbnoborder">
        	<td width="20%">图书名称</td>
        	<td width="20%">作者</td>
        	<td width="20%">借阅时间</td>
        	<td width="20%">应还时间</td>
        	<td width="20%">归还</td>
        </tr>
        <?php
		if(!empty($guoqi))
		{
			foreach($guoqi as $v)
			{
		?>
    	<tr>
        	<td width="20%"><?php echo '<a href="book_view.php?bookid=' . $v['bid'] . '">' . $v['name'] . '</a>';?></td>
			<td><?php echo $v['author'];?></td>
            <td><?php echo d($v['borrowdate']);?></td>
            <td><?php echo d($v['backdate']);?></td>
            <td><a href="book_borrow_back.php?act=back&bid=<?php echo $v['bid'];?>">点此归还</a></td>
        </tr>
        <?php
			}
		}
		else
		{
			echo '<tr><td colspan="6">暂无到期图书</td></tr>';
		}
		?>
    </table>
    </div>
</div>
<?php echo $copyright;?>
</body>
</html>